<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.DriverManager" %>
<%@ page import="java.sql.PreparedStatement" %><%--
  Created by IntelliJ IDEA.
  User: 17126
  Date: 2022/5/20
  Time: 15:55
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>注册信息</title>
</head>
<body>
<jsp:useBean id="user" class="com.mySql.userDate"/>
<jsp:setProperty name="user" property="*"/>
<%
    try {
        Class.forName("com.mysql.cj.jdbc.Driver");
        String url = "jdbc:mysql://localhost:3306/user";
        String username = "root";
        String password = "root";
        Connection conn = DriverManager.getConnection(url, username, password);
        String sql = "insert into user.userdate(username, password) values(?,?)";
        PreparedStatement ps = conn.prepareStatement(sql);
        ps.setString(1, user.getUsername());
        ps.setString(2, user.getPassword());
        int row = ps.executeUpdate();
        if (row > 0) {
            out.print("成功注册" + row + "位用户！");
        }
        ps.close();
        conn.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
%>
</body>
</html>
